package bomberman.rule;

import bomberman.BombermanGameLevel;
import bomberman.entity.Bomb;
import bomberman.entity.Bomberman;
import gameframework.game.IllegalMoveException;
import gameframework.game.MoveBlockerRuleApplierDefaultImpl;

public class BombermanMoveBlockers extends MoveBlockerRuleApplierDefaultImpl {

	public void moveBlockerRule(Bomberman b, Bomb bb) throws IllegalMoveException {
		//if the bomberman is front of a bomb and can catch bombs
		//Not when he is on a bomb (he just dropped it)
		if (b.canCatchBomb() && !b.isOnABomb())
		{
			b.decNumberOfBombsToCatch();
    		BombermanGameLevel.medUniverse.getUniverse().removeGameEntity(bb);
    		b.upNumberOfBombs();
		}
		
		// When a bomberman is on a bomb (when he drop one) he must be able to move.
		// In other condition the bomberman can't walk over a bomb
		if (!b.isOnABomb() || 
				(b.getBombPos().getX() != bb.getPosition().getX() ||
						b.getBombPos().getY() != bb.getPosition().getY())) {
			throw new IllegalMoveException();
		}
	}
}
